//
//  SendCommentsViewController.m
//  cityStar
//
//  Created by joyban on 15-1-28.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "SendCommentsViewController.h"
#import "RJPlaceHolderTextView.h"
#import "UIColor+FlatUI.h"

@interface SendCommentsViewController ()<UITextViewDelegate>

@property(nonatomic,weak)IBOutlet RJPlaceHolderTextView *conentText;
@property (nonatomic, strong) NSString *commndityID;

@end

@implementation SendCommentsViewController

-(id)initWithCommodityID:(NSString *)commodityID
{
    self = [super init];
    if (self) {
        self.commndityID = commodityID;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"发评论";
    self.conentText.placeholder = @"请输入内容";
    self.conentText.placeholderColor = [UIColor colorFromHexCode:@"c4c4c4"];
//    [self.conentText becomeFirstResponder];
    __weak typeof(self)weakSelf = self;
    [self addBackButton];
    [self addRightButtonWithTitle:@"发送" actionBlock:^{
//        [weakSelf.navigationController popViewControllerAnimated:YES];
        [weakSelf sendMessage];

    }];
}

-(void)sendMessage
{
    if (self.conentText.text.length < 10) {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"评论不能少于10个字" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertView show];
    }else{
    NSDictionary *parameters = @{@"goods":self.commndityID,
                                 @"comment":self.conentText.text
                                 };
    [HttpRequestManager postMethod:KinterFace_GoodsComment parameters:parameters completedMainBlock:^(BOOL success, id response, NSString *errMsg) {
        DLog(@"%@",response);
        if (success) {
            [SVProgressHUD showSuccessWithStatus:@"评论成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [SVProgressHUD showErrorWithStatus:errMsg];
        }
    }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    return YES;
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车，即按下return
        //在这里做你响应return键的代码
        return NO; //这里返回NO，就代表return键值失效，即页面上按下return，不会出现换行，如果为yes，则输入页面会换行
    }
    
    return YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
